package com.ruoyi.anchor.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.anchor.domain.AnchorManagement;
import com.ruoyi.anchor.service.IAnchorManagementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 主播管理Controller
 * 
 * @author ruoyi
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/anchor/anchor")
public class AnchorManagementController extends BaseController
{
    @Autowired
    private IAnchorManagementService anchorManagementService;

    /**
     * 查询主播管理列表
     */
    @PreAuthorize("@ss.hasPermi('anchor:anchor:list')")
    @GetMapping("/list")
    public TableDataInfo list(AnchorManagement anchorManagement)
    {
        startPage();
        List<AnchorManagement> list = anchorManagementService.selectAnchorManagementList(anchorManagement);
        return getDataTable(list);
    }

    /**
     * 导出主播管理列表
     */
    @PreAuthorize("@ss.hasPermi('anchor:anchor:export')")
    @Log(title = "主播管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AnchorManagement anchorManagement)
    {
        List<AnchorManagement> list = anchorManagementService.selectAnchorManagementList(anchorManagement);
        ExcelUtil<AnchorManagement> util = new ExcelUtil<AnchorManagement>(AnchorManagement.class);
        util.exportExcel(response, list, "主播管理数据");
    }

    /**
     * 获取主播管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('anchor:anchor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(anchorManagementService.selectAnchorManagementById(id));
    }

    /**
     * 新增主播管理
     */
    @PreAuthorize("@ss.hasPermi('anchor:anchor:add')")
    @Log(title = "主播管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AnchorManagement anchorManagement)
    {
        return toAjax(anchorManagementService.insertAnchorManagement(anchorManagement));
    }

    /**
     * 修改主播管理
     */
    @PreAuthorize("@ss.hasPermi('anchor:anchor:edit')")
    @Log(title = "主播管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AnchorManagement anchorManagement)
    {
        return toAjax(anchorManagementService.updateAnchorManagement(anchorManagement));
    }

    /**
     * 删除主播管理
     */
    @PreAuthorize("@ss.hasPermi('anchor:anchor:remove')")
    @Log(title = "主播管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(anchorManagementService.deleteAnchorManagementByIds(ids));
    }
}
